<?php

/**
 * @Author: wuchenge
 * @Date:   2022-04-20 10:58:37
 * @Email: ligui0506@126.com
 * @Descript:
 */
namespace App\Requests;

use Illuminate\Http\Request;

class LevelRequest extends FormRequest
{
    /**
     * @param Request $request
     */
    public function rules(Request $request)
    {
        $params = $request->input();
        $id     = 0;
        if (array_key_exists('id', $params)) {
            $id = $params['id'];
        }
        return [
            'name'       => [
                'required',
                'min:1',
                'max:10',
                'unique:levels,name,' . $id,
            ],
            'self_tip'   => [
                'required',
                'integer',
                'min:0',
                'max:1000',
            ],
            'parent_tip' => [
                'required',
                'integer',
                'min:0',
                'max:1000',
            ],
            'color'      => [
                'required',
                'string',
            ],

        ];
    }

    public function messages()
    {
        return [
            'name.required'       => '名称必须',
            'name.unique'         => '名称已存在',
            'self_tip.required'   => '自身返点必须',
            'parent_tip.required' => '上级返点必须',
            'color.required'      => '颜色返点必须',
        ];
    }

    /**
     * @var array
     */
    public $scene = [
        'admin.level.create' => ['name', 'self_tip', 'parent_tip', 'color'],
        'admin.level.update' => ['name', 'self_tip', 'parent_tip', 'color'],
    ];
}
